﻿@model EventSys.BussinesEntities.Director

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Director</legend>

        <div class="editor-label">
            @Html.HiddenFor(model => model.idDirector)
        </div>
        <div class="editor-field">
            @Html.HiddenFor(model => model.idDirector)
            @Html.ValidationMessageFor(model => model.idDirector)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DNI)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.DNI, new {style = "width: 150px;", placeholder = "Ingrese DNI",minlength="8",maxlength="8", id="dni"})
            @Html.ValidationMessageFor(model => model.DNI)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Nombre)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Nombre,new {style = "width: 280px;", placeholder = "Ingrese Nombres"})
            @Html.ValidationMessageFor(model => model.Nombre)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Apellidos)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Apellidos,new {style = "width: 280px;", placeholder = "Ingrese Apellidos"})
            @Html.ValidationMessageFor(model => model.Apellidos)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Dirección)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Dirección,new {style = "width: 280px;", placeholder = "Ingrese Dirección"})
            @Html.ValidationMessageFor(model => model.Dirección)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Telefono)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Telefono,new {style = "width: 280px;", placeholder = "Ingrese Telefono"})
            @Html.ValidationMessageFor(model => model.Telefono)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Celular)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Celular,new {style = "width: 280px;", placeholder = "Ingrese Celular"})
            @Html.ValidationMessageFor(model => model.Celular)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Email,new {style = "width: 280px;", placeholder = "Ingrese Email"})
            @Html.ValidationMessageFor(model => model.Email)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.idCarrera)
        </div>
        <div class="editor-field">
            @*@Html.EditorFor(model => model.idCarrera)*@
            @Html.DropDownList("idCarrera")
            @Html.ValidationMessageFor(model => model.idCarrera)
        </div>

        <p>
            <input type="submit" value="EDITAR" class="k-button"/>
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {

    @Scripts.Render("~/bundles/jqueryval")
    
<script type="text/javascript">
    $(function () {
        $("#dni").focusout(function () {
            var dni = $(this).val();
            //alert(dni);
            $.ajax({
                url: "/Director/validarDni?dni=" + dni,
                success: (function (data) {
                    //alert(dni);
                    if (data.existe == true) {
                        alert("El DNI ya existe");
                        $("#dni").focus().select();
                    }
                })
            })
        })
    })

    $(document).ready(function () {
        $("#dni").keydown(function (e) {
            // Permite: backspace, delete, tab, escape, enter and .
            if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
                // Permite: Ctrl+A -----> para seleccionar todo el texto de la casilla
                (e.keyCode == 65 && e.ctrlKey === true) ||
                // Perimite: home, end, left, right
                (e.keyCode >= 35 && e.keyCode <= 39)) {
                // deja que suceda todo, no hacer nada
                return;
            }
            // Se asegura de que se trata de un número y detiene la pulsación de tecla
            if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
                e.preventDefault();
            }
        });
    });

    //$(this).load(function () {
    //    $("#dni").focus();
    //})

</script>


}
